import csv
ht=['ComingOfAge', 'falldiy', 'gaminglife', 'interiordesign', 'oneyourthere', 'sfxmakeup', 'tiktokfood', 'worldseries', 'halloweenishere', 'meleaving', 'yellow', 'yougotthis', 'mycostume', 'animation', 'youwantmore', 'halloweenlook', 'mypfp', 'nativefamily', 'welldone', 'happyhalloween', 'OhNo', 'holidaytiktok', 'rnbvibes', 'carsoftiktok', 'homeoffice', 'myrecommendation', 'fallfashion', 'familyimpression', 'myhobby', 'neonshadow', 'fanedit', 'stemlife', 'motivationmonday', 'wip', 'veteransday', 'holidaycountdown', 'whereilive', 'bekind', 'onhold', 'diwali', 'WeekendVibes', 'bakingszn', 'RoomTour', 'foodtiktok', 'growupwithme', 'holidaysourway', 'tabletop', 'nbadraft', 'recordsday', 'ourtype', 'nonuancenovember', 'artmas', 'gamingsetup', 'theatrekids', 'needtoknow', 'whenwewereyounger', 'graphicdesign', 'inkdrawing', 'fallguysmoments', 'familyrecipe', 'onlinedating', 'watchmegrow', 'givingthanks', 'readysetshop', 'diceroll', 'smallbusiness', 'holidayvibes', 'coldweather', 'givingszn', 'happyholidays', 'homecooked', 'easydiy', 'wildanimals', 'holidaymusic', 'howbizarre', 'selfimprovement', 'ImAGhost', 'personalfinance', 'housetour', 'thinkingabout', 'holidaycrafts', 'happyhanukkah', 'RatatouilleMusical', 'catchphrases', 'ootd', 'comfortfood', 'holidaydecor', 'raisedby', 'goodmorning', 'makeitvogue', 'festivefashion', 'gamenight', 'artmas', 'haventseen', 'planttiktok', 'productivity', 'lovestory', 'wishlist', 'hellowinter', 'YearOnTikTok', 'nbaisback', 'perfectgifts', 'holidaytreats', 'wrappinggifts', 'feliznavidad', 'timewarpjump', 'christmas2020', 'MyHaul', 'cozyathome', 'myhaul', 'winterfit', 'withouttellingme', 'hyperfixated', 'whatilearned',  'WordsOfWisdom',  'rareaesthetic', 'welcome2021', 'dailyvlog', 'easyrecipe', 'mystyle', 'Bye2020', 'myroutine', 'gamergoals', 'projectcar', 'homemade', 'inlove', 'GreenScreenScan', 'tortillatrend', 'NFLplayoffs', 'FitnessRoutine', 'IsThisAvailable', 'wee', 'weirdpets', 'fitnessroutine',  'moneytok', 'nflplayoffs', 'healthycooking', 'nhlfaceoff', 'groupchat', 'NHLFaceOff', 'winterfashion', 'skincare101', 'zodiacsign', 'homeimprovement', 'seashanty', 'cleantok', 'visionboard', '2021affirmations', 'mlkday', 'joblife', 'foodie', 'timewarpwaterfall', 'plantparent', 'WinterMagic', 'notaperfectperson', 'tiktoktutorial', 'cocinando', 'OlympicsCountdown', 'couplethings', 'clingypet', 'meditation101', 'winterbeautytips', 'tiktokdiy', 'typing', 'roundofapplause', 'xgamesmode', 'feelinggood', 'RoyalRumble', 'emophase', 'wintersports', 'makeblackhistory', 'relationshipstorytime', 'albumcover', 'stepbystep', 'fetapasta', 'womeninsports', 'healthyheart', 'imbusyrightnow', 'beautyhacks', 'tiktoktailgate', 'puppybowl', 'superbowllv', 'valentinesdiy', 'melaninmagic', 'coversforlovers', 'kissyourpet', 'womeninstem', 'lunarnewyear', 'perfectmatch', 'galentinesday', 'valentinesday', 'loveyourinsecurities', 'tiktokfashionmonth', 'blackcreatives', 'colddays', 'mifamilia', 'careeradvice', 'stopasianhate', 'perfectdrink', 'snowstorm', 'carhacks', 'homeproject', 'blackandproud', 'dramaticmoments', 'bakedoats', 'homecook', 'laughingduet', 'yoga101', 'somethingyoulearned', 'upcycling', 'fantheory', 'tiktokfitness', 'gamingtiktok', 'seitan', 'glasspainting', 'whenwomenwin', 'science101', 'thriftflip', 'Lifestyle', 'tiktokwildlifeday', 'dayandnight']
hts=[h.lower().replace('#','') for h in ht]
ht=[]
for item in hts:
    if item not in ht:
        ht.append(item)
ids={}
with open('D:\\Work\\Tool\\tiktok\\all\\infos_d7_r.tsv', 'r', encoding='utf-8', newline='\n') as filename_input:
    reader = csv.reader(filename_input, delimiter='\t')
    next(reader)
    i=0
    for line in reader:
        if int(line[5])<200:
            if ht[int(line[0])-1] in ids.keys():
                ids[ht[int(line[0])-1]].append(line[1])
            else:
                ids[ht[int(line[0])-1]]=[line[1]]

with open('E:\\data_pi\\htids_top200.tsv','w', encoding='utf-8',newline='\n') as fout:
    writer = csv.writer(fout, delimiter='\t')
    for key in ids.keys():
        for id in ids[key]:
            writer.writerow([key,id])